﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AutoGam
{
    public class Com
    {
        public static String Left(String data, int len)
        {
            int curLen = 0;
            int curIdx = 0;
            String retStr = "";
            while (curIdx <= data.Length - 1)
            {
                Byte[] curCharBytes = Encoding.GetEncoding("GBK").GetBytes(data[curIdx].ToString());
                if (curLen + curCharBytes.Length <= len)
                {
                    curLen += curCharBytes.Length;
                    retStr += data[curIdx].ToString();
                    curIdx++;
                }
                else
                {
                    break;
                }

            }

            return retStr;
        }

        public static String[] Split(String data)
        {
            if (data == null) data = "";
            int curLen = 0;
            int curIdx = 0;
            String[] ret = new String[3] { "", "", "" };

            for (int i = 0; i < data.Length; i++)
            {
                Byte[] curCharBytes = Encoding.GetEncoding("GBK").GetBytes(data[i].ToString());
                if (curLen + curCharBytes.Length > 8)
                {
                    curIdx++;
                    curLen = 0;
                }
                if (curIdx >= 3)
                {
                    break;
                }
                ret[curIdx] += data[i];
                curLen += curCharBytes.Length;
            }

            return ret;
        }
    }
}
